package tcp

import (
	net "gitee.com/ameise84/e3net"
	"gitee.com/ameise84/e3utils/str_conv"
)

var (
	_srvHandler = &serverHandler{}
)

type serverHandler struct {
}

func (ts *serverHandler) OnNewConnect(tag net.Tag, conn net.Conn) net.ConnContext {
	id := str_conv.ToString(conn.ID())
	actor, ok := _gActorServer.StartNetActor(id)
	if !ok {
		return nil
	}
	rc := takeRawContext()
	rc.onInit(conn, actor)
	return rc
}

func (ts *serverHandler) OnClosedConnect(ctx net.ConnContext) {
	rc := ctx.(*rawContext)
	rc.onClosed()
	freeRawContext(rc)
}
